import Vue from 'vue'
import App from '@/App'
import router from '@/router'                 // api: https://github.com/vuejs/vue-router
import store from '@/store'                   // api: https://github.com/vuejs/vuex
import VueCookie from 'vue-cookie'            // api: https://github.com/alfhen/vue-cookie
import '@/element-ui'                         // api: https://github.com/ElemeFE/element
import '@/icons'                              // api: http://www.iconfont.cn/
import '@/element-ui-theme'
import '@/assets/scss/index.scss'
import httpRequest from '@/utils/httpRequest' // api: https://github.com/axios/axios
import httpRequests from '@/utils/httpRequests'
import refreshRequest from '@/utils/refreshRequest'
import { isAuth } from '@/utils'
import cloneDeep from 'lodash/cloneDeep'
import MintUI from 'mint-ui'
// fade/zoom 等
import 'element-ui/lib/theme-chalk/base.css'
// collapse 展开折叠
import CollapseTransition from 'element-ui/lib/transitions/collapse-transition'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'
import VXETablePluginElement from 'vxe-table-plugin-element'
import 'vxe-table-plugin-element/dist/style.css'
import Print from 'vue-print-nb'

Vue.use(Print)
VXETable.use(VXETablePluginElement)
Vue.use(VXETable)
Vue.component(CollapseTransition.name, CollapseTransition)
// Vue.use(Sortable)
Vue.use(MintUI)
Vue.use(VueCookie)
Vue.config.productionTip = false

// 非生产环境, 适配mockjs模拟数据                 // api: https://github.com/nuysoft/Mock
if (process.env.NODE_ENV !== 'production') {
  require('@/mock')
}

// 挂载全局
Vue.prototype.$http = httpRequest // ajax请求方法
Vue.prototype.$https = httpRequests //
Vue.prototype.$services = refreshRequest
Vue.prototype.isAuth = isAuth     // 权限方法

// 保存整站vuex本地储存初始状态
window.SITE_CONFIG['storeState'] = cloneDeep(store.state)

Vue.filter('dateTimeFormat', (value) => {
  var time = new Date(+value)
  var rightTwo = (v) => {
    v = '0' + v
    return v.substring(v.length - 2, v.length)
  }
  if (time == null) return
  var year = time.getFullYear()
  var month = time.getMonth() + 1
  var date = time.getDate()
  var hours = time.getHours()
  var minutes = time.getMinutes()
  var seconds = time.getSeconds()
  return year + '-' + rightTwo(month) + '-' + rightTwo(date) + ' ' + rightTwo(hours) + ':' + rightTwo(minutes) + ':' + rightTwo(seconds)
})

Vue.filter('dateTimeTFormat', (value) => {
  var arr = value.split('T')
  var d = arr[0]
  var darr = d.split('-')
  var t = arr[1]
  var tarr = t.split('.000')
  var marr = tarr[0].split(':')
  var dd = parseInt(darr[0]) + '/' + parseInt(darr[1]) + '/' + parseInt(darr[2]) + ' ' + parseInt(marr[0]) + ':' + parseInt(marr[1]) + ':' + parseInt(marr[2])
  return dd
})

Vue.filter('dateFormat', (value) => {
  var time = new Date(+value)
  var rightTwo = (v) => {
    v = '0' + v
    return v.substring(v.length - 2, v.length)
  }
  if (time == null) return
  var year = time.getFullYear()
  var month = time.getMonth() + 1
  var date = time.getDate()
  return year + '-' + rightTwo(month) + '-' + rightTwo(date)
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
})
